<html>
<head>
<link rel="stylesheet" href="imas.css" type="text/css">
</head>
<body>
<?php
include("config.php");

if (!isset($_POST['authuser'])) {
	echo "<form method=post action=\"dbsetup_added.php\">\n";
	echo "<h3>This script will set up added table for IMathAS</h3>\n";
	echo "<p><b>Before submitting this form</b> be sure you have edited the config.php file to match the settings for your server</p>\n";
	echo "<p><fieldset><legend>Database Table Added </legend>\n";
	echo "<span class=form>Username of MySQL user authorized to create new database tables</span>";
	echo "<span class=formright><input type=text name=authuser></span><br class=form>\n";
	echo "<span class=form>Password</span>";
	echo "<span class=formright><input type=password name=authpass></span><br class=form>\n";
	echo "</fieldset>\n";
	echo "<div class=submit><input type=submit value=\"Set up the new table\"></div>\n";
	echo "</form>\n";
	echo "<p><sup>*</sup>On some shared servers, your read/write MySQL user can only create new database users and databases ";
	echo "through the provided web administration tool or control panel.  In this case, you will need to create the database and ";
	echo "database users before running this script.  Be sure to modify the config.php file to reflect your chosen database and ";
	echo "database user name.</p>\n";
	echo "</body></html>\n";
	exit;
}

$authuser = $_POST['authuser'];
$authpass = $_POST['authpass'];

$link = mysql_connect($dbserver,$authuser, $authpass) 
  or die("Could not connect : " . mysql_error());

mysql_select_db($dbname) 
  or die("Could not select database");

$sql = 'CREATE TABLE `imas_reports` ('
        . ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
        . ' `userid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
        . ' `username` VARCHAR(20) NOT NULL, '
        . ' `fullname` VARCHAR(50) NOT NULL, '
        . ' `courseid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
        . ' `reportid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
        . ' `uploaddate` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
        . ' `filesize` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
        . ' `filename` VARCHAR(254) NOT NULL, '
        . ' INDEX (`userid`), INDEX (`courseid`)'
        . ' )'
        . ' TYPE = innodb'
        . ' COMMENT = \'Which reports each student upload\';';
mysql_query($sql) or die("Query failed : $sql " . mysql_error());

echo 'imas_reports created<br/>';

?>
</body>
</html>
